package com.woniuxy.warehouse.controller;

import com.woniuxy.commons.entity.warehouse.IoWarehouse;
import com.woniuxy.commons.entity.warehouse.dto.TimeAndOrderDto;
import com.woniuxy.commons.result.Result;
import com.woniuxy.warehouse.service.StockOutService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:SHEAndme
 * @Todo:TODO 出库Controller
 * @DateTime:2022/4/19 10:01
 **/
@RestController
@RequestMapping("/warehouse/stockOut")
public class StockOutControlller {
    @Resource
    private StockOutService stockOutService;

    @ApiOperation(value = "出库单首页")
    @PostMapping("/findAllStockOutInHomePage/{pageNum}/{pageSize}")
    public Result findAllStockInHomePage(@PathVariable("pageNum") Integer currentPage,
                                         @PathVariable("pageSize") Integer pageSize,
                                         @RequestBody TimeAndOrderDto timeAndOrderDto){


        return  stockOutService.findAllStockOutHomePage(currentPage,pageSize,timeAndOrderDto);
    }

    /**
     * 分页查询
     *
     * @param ioWarehouse 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "/findAll", httpMethod = "POST", response = Result.class)
    @PostMapping("/findAll/{pageNum}/{pageSize}")
    public Result findAll(@PathVariable("pageNum") Integer currentPage,
                          @PathVariable("pageSize") Integer pageSize,
                          @RequestBody IoWarehouse ioWarehouse) {
        System.out.println("到达了findByPage");
        return stockOutService.queryByPage(currentPage,pageSize,ioWarehouse);
    }



    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     * TODO 不建议使用
     */
    @PostMapping("/findby/{id}")
    public Result queryById(@PathVariable("id") Integer id) {
        Result<List<IoWarehouse>> result = stockOutService.queryById(id);
        return result;

    }

    /**
     * 新增数据
     *
     * @param ioWarehouse 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新建出库单")
    @PostMapping("/addStockOut")
    public Result add(@RequestBody IoWarehouse ioWarehouse) {
        return stockOutService.addStockOutOrder(ioWarehouse);
    }

    /**
     * 编辑数据
     *
     * @param ioWarehouse 实体
     * @return 编辑结果
     */
    @PutMapping("/update")
    public Result edit(@RequestBody IoWarehouse ioWarehouse) {
        System.out.println("到达了修改update");
        System.out.println(ioWarehouse.getId());
        return stockOutService.update(ioWarehouse);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/deleteby/{id}")
    public Result<Boolean> deleteById(@PathVariable("id") Integer id) {
        System.out.println("id:"+id);
        return Result.ok(stockOutService.deleteById(id));
    }

    /**

     * @description TODO 逻辑删除 将状态改为0 0 为删除
     */

}
